#-*- coding: UTF-8 -*- 
 
'''
1、读取指定目录下的所有文件
2、读取指定文件，输出文件内容
3、创建一个文件并保存到指定目录
'''
import os
import json

feaNames=[]#记录已经合并的feature名称，如果已经有了，不做重复处理
allFeatures=[]#记录所有的要素
featureCollc=None#记录总的featureCollec
# 遍历指定目录，显示目录下的所有文件名
def eachFile(filepath):
    list = os.listdir(filepath) #列出文件夹下所有的目录与文件
    for i in range(0,len(list)):
        path = os.path.join(filepath,list[i])
        if os.path.isfile(path):
            file_object = open(path)
            file_context = file_object.read()
            print(path)
            print(file_context)
#     geojson_obj=json.loads(geojson_data)
#     featureCollc=geojson_obj
#     features=geojson_obj['features']
#     for feature in features:
#         property=feature['properties']
#         name=property['name']
#         if name not in feaNames:#没处理过的才做如下处理：
#             allFeatures.append(feature)
#   featureCollc['features']=allFeatures
#   fopen = open(filename, 'w')
#   aLine = json.dumps(featureCollc)
#   fopen.write('%s%s' % (aLine, os.linesep))
# 读取文件内容并打印
def readFile(filename):
  fopen = open(filename, 'r') # r 代表read
  for eachLine in fopen:
    print "读取到得内容如下：",eachLine
  fopen.close()
   
# 输入多行文字，写入指定文件并保存到指定文件夹
def writeFile(filename):
  fopen = open(filename, 'w')
  print "\r请任意输入多行文字"," ( 输入 .号回车保存)"
  while True:
    aLine = raw_input()
    if aLine != ".":
      fopen.write('%s%s' % (aLine, os.linesep))
    else:
      print "文件已保存!"
      break
  fopen.close()
 
if __name__ == '__main__':
  filePathC = "D:\\data_dir2\\DJgeojson"
  eachFile(filePathC)